/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Fuente;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;

/**
 *
 * @author Julio Lemus
 */
public class panelBalanza extends JPanel {
    double rotacion;
    double centrox, centroy;
    
    public panelBalanza(Dimension d){
        this.setPreferredSize(d);
        this.setSize(d);
        this.setVisible(true);
        this.repaint();
        this.centrox = this.size().width/2;
        this.centroy = this.size().height/2;
        rotacion = 0;
    }
    
    @Override
    public void paintComponent (Graphics g){
        //se inicializa java2d
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(new GradientPaint(0, 0, new Color(131,131,131), Float.valueOf(this.getSize().width), 0, new Color(188,194,236)));
        g2.fill(g2.getClip());
        AffineTransform oldt = g2.getTransform();
        g2.transform(AffineTransform.getRotateInstance(Math.toRadians(rotacion),this.centrox,this.centroy));
        g2.setColor(new Color(200,10,10));
        //se dibuja la figura, junto a una linea que nos servira para apreciar mejor la rotacion
        g2.setPaint(new GradientPaint((float) this.centrox-100, (float) this.centroy, new Color(0,0,0), (float) this.centrox+100, (float) this.centroy, new Color(0,0,0)));
        g2.fill(new Rectangle2D.Double( this.centrox-20, this.centroy-20, 40, 40));
        g2.fill(new Rectangle2D.Double( this.centrox-200, this.centroy-10, 400, 20));
        g2.setColor(new Color(0,0,200));
        g2.setStroke(new BasicStroke(4.0f));
//        g2.draw(new Line2D.Double(this.centrox,this.centroy,this.centrox+100,this.centroy));
        g2.setFont(new Font("Arial", Font.BOLD, 12));
        g2.drawString("  R=" + rotacion+"°",(float) this.centrox+100 ,(float) this.centroy);
        g2.setTransform(oldt);
        
//        g2.setColor(new Color(0,0,0));
//        g2.setFont(new Font("Arial", Font.PLAIN, 12));
//        g2.drawString("Rotación (Grados) = " + rotacion + "°", 10,25);
//        g2.drawString("Rotación (Radianes) = " + Math.toRadians(rotacion), 10,50);
        
//        this.setBackground(Color.WHITE);
        //Creación del Rectangle2D
//        g2.setColor(Color.red);
//        g2.setStroke(new BasicStroke(3.0f));
//        Rectangle2D r = new Rectangle2D.Float(0.0f, 0.0f, 300.0f,40.0f);
//        g2.draw(r);
//        g.setColor( new Color( 255, 0, 0 ) );
//        g.fillRect( 15, 25, 100, 20 );
//        g.drawString(""+g.getColor(), 130, 40 );
        
    }
    
    //aplica la rotacion en grados
  public void setRotate(double r){
    this.rotacion = r;
  }
}
